package com.hsy.baoinbao.modules.order.adapter;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.deparse.dpframe.ui.adapter.DPBaseAdapter;
import com.hsy.baoinbao.R;

import java.util.HashMap;
import java.util.List;

/**
 * Created by MartinDKent on 2016/3/23.
 */
public class ReceivingUndoneAdapter extends DPBaseAdapter<HashMap<String, String>> {
    private LayoutInflater inflater;
    private Context mContext;

    public ReceivingUndoneAdapter(Context context) {
        super();
        init(context);
    }

    public ReceivingUndoneAdapter(Context context, List<HashMap<String, String>> data) {
        super(data);
        init(context);
    }

    private void init(Context context) {
        this.inflater = LayoutInflater.from(context);
        this.mContext = context;
    }

    @Override
    public CommonBaseViewHolder<HashMap<String, String>> getHolder(int position) {
        return new ViewHolder();
    }

    class ViewHolder extends CommonBaseViewHolder<HashMap<String, String>> {
        private TextView item_receive_title, address, time, name_merchant;
        private ImageView image, phone;

        @Override
        public View create(int position) {
            View view = inflater.inflate(R.layout.item_receiving_list, null);
            item_receive_title = (TextView) view.findViewById(R.id.item_receive_title);
            address = (TextView) view.findViewById(R.id.address);
            time = (TextView) view.findViewById(R.id.time);
            image = (ImageView) view.findViewById(R.id.image);
            phone = (ImageView) view.findViewById(R.id.phone);
            name_merchant = (TextView) view.findViewById(R.id.name_merchant);
            return view;
        }

        @Override
        public void update(final HashMap<String, String> data) {
            phone.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Uri uri = Uri.parse("tel:" + data.get("tel"));   //拨打电话号码的URI格式

                    Intent it = new Intent();   //实例化Intent

                    it.setAction(Intent.ACTION_CALL);   //指定Action

                    it.setData(uri);   //设置数据

                    mContext.startActivity(it);//启动Acitivity
                }
            });
            item_receive_title.setText(data.get("item_receive_title"));
            address.setText(data.get("address"));
            time.setText(data.get("time"));
            image.setImageResource(R.mipmap.red_icon);
            name_merchant.setText(data.get("name_merchant"));
        }

    }
}